package com.lenovo.testreport.qa.web.compatibility.controller;

import com.lenovo.testreport.qa.web.compatibility.model.QaWebCompatibilityReport;
import com.lenovo.testreport.qa.web.compatibility.service.QaWebCompatibilityReportService;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author CJF
 * @date 2018/11
 * @version Updated at 2019/05/24 By Howie Lu
 * <p>
 * 主要对report主表进行操作，查询报告
 */
@Controller
@RequestMapping("/qa/report")
public class QaWebReportController {
    @Autowired
    private QaWebCompatibilityReportService qaWebCompatibilityReportService;

    //查找所有报告
    @RequestMapping("/FindAllReport")
    public @ResponseBody
    Object FindAllReport(HttpServletRequest request) {
        return qaWebCompatibilityReportService.findAllReport(request.getParameter("tablename"));
    }

    //按时间和版本查找报告
    @RequestMapping("/FindAllReportByTime")
    public @ResponseBody
    Object FindAllReportByTime(HttpServletRequest request) {

        String version = "";
        if (request.getParameter("version") != "") {
            version = request.getParameter("version").replace("\"", "");
        }
        version += "%";
        List<QaWebCompatibilityReport> list = qaWebCompatibilityReportService.findReportByTime(request.getParameter("tablename"), request.getParameter("start"), request.getParameter("end"), version);
        return list;
    }

    //按类型查找报告
    @RequestMapping("/FindByType")
    public @ResponseBody
    Object FindByType(HttpServletRequest request) {


        return qaWebCompatibilityReportService.findByType(request.getParameter("tablename"), request.getParameter("type"));
    }

    //查找所有版本号
    @RequestMapping("/FindAllVersion")
    public @ResponseBody
    Object FindAllVersion(HttpServletRequest request) {

        return qaWebCompatibilityReportService.findAllVersion(request.getParameter("tablename"));
    }
}
